import java.util.Arrays;

/**
 * 2731. 移动机器人
 */
public class No2731 {
    private final long MOD = (long) (Math.pow(10, 9) + 7);

    public int sumDistance(int[] nums, String s, int d) {
        int n = nums.length;
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'R') a[i] = nums[i] + d;
            else a[i] = nums[i] - d;
        }

        Arrays.sort(a);
        long answer = 0;
        /*
        从小到大枚举 a[i]，此时左边有 i 个数都不超过 a[i]，那么 a[i] 与其左侧机器人的距离之和为
         (a[i]−a[0])+(a[i]−a[1])+⋯+(a[i]−a[i−1]) = i⋅a[i]−(a[0]+a[1]+⋯+a[i−1])
        */
        long preSum = 0;
        for (int i = 1; i < n; i++) {
            preSum += a[i - 1];
            answer += (i * (a[i]) - preSum) % MOD;
        }
        return (int) (answer % MOD);
    }
}
